import instance from "../utils/axios";
const BASE_URL = import.meta.env.VITE_BASE_URL as string;

export interface IList<T> {
    total: number;
    list: T[];
}

export type IListRes<T> = Promise<IList<T>>;

export interface IAttach {
    name: string;
    url: string;
}

// 发送get请求
export const get = async (url: string, params: object = {}, config: object = {}) => {
    try {
        return instance.get(BASE_URL + url, { params, ...config });
    } catch (error) {
        return Promise.reject(error);
    }
};

// 发送post请求
export const post = async (url: string, data: object, config = {}) => {
    try {
        return instance.post(BASE_URL + url, data, { ...config });
    } catch (error) {
        return Promise.reject(error);
    }
};

// 上传图片
export const postUploadImg = async (url: string, data: object, config: object) => {
    try {
        return instance.post(BASE_URL + url, data, {
            headers: {
                "Content-Type": "multipart/form-data",
                ...config,
            },
        });
    } catch (error) {
        return Promise.reject(error);
    }
};
